<?php
/**
 * Created by PhpStorm.
 * User: zhaox
 * Date: 2018/1/4
 * Time: 15:41
 */
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;

class ImageController extends Controller {
    public function upload(){
        $file = Input::file('file');
        if ($file->isValid()) {
            $entension = $file -> getClientOriginalExtension(); //上传文件的后缀.
            $newName = date('YmdHis').mt_rand(100,999).'.'.$entension;
            $path = $file ->move('/var/www/travel/public/uploads',$newName);
            $filepath = '/uploads/'.$newName;
            return response()->json(['state'=>true, 'path'=>$filepath,]);
        }
        return response()->json(['state'=>false, 'errmsg'=>'上传失败',]);
    }
}
